#!/bin/bash
#
 while true; do
    netstat -ant 2>/dev/null | \
    awk '
        $6=="LISTEN"     {L++}
        $6=="ESTABLISHED"{E++}
        END{printf strftime("[%F %T]") " LISTEN=%d  ESTABLISHED=%d\n", L, E}
    '
    sleep 1
done
